﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KeywordAuction
{
    public class Adspot
    {
        public Adspot()
        {
            clickThroughtRates = new List<double>();
            bitting = new List<AdvertiserBidding>();
            Id = Guid.NewGuid().ToString();
        }
        public string Name { get; set; }
        public string Id { get; set; }
        public int Traffic { get; set; }
        public int GetIndexAdvertiser(AdvertiserBidding advertiser)
        {
            var ordered = Bitting.OrderByDescending(p => p.Bid).ToList();
            if(Bitting.Contains(advertiser))
            {
                for (int i = 0; i < Bitting.Count; i++)
                {
                    if (ordered[i] == advertiser)
                    {
                        return i;
                    }
                }
            }
            return -1;
        }

        public AuctionHost AuctionHost { get; set; }
        private List<double> clickThroughtRates;
        public List<double> ClickThroughtRates
        {
            get {return clickThroughtRates;}
            set{ clickThroughtRates = value.OrderByDescending(p=>p).ToList();
        } }
        private List<AdvertiserBidding> bitting;
        public List<AdvertiserBidding> Bitting { 
            get {return bitting;}
            set {bitting = value.OrderByDescending(p => p.Bid).ToList();}
        }


        public double GetPaymentValue(int index)
        {
            return AuctionHost.AuctionMechanism.GetPaymentValue(index, ClickThroughtRates, Bitting);
        }
    }
}
